<?php
echo '<div id="header-login">';
    // Simple Facebook Connect Plugin installed?
    $usefacebook = false;
    if (function_exists('sfc_version')) {
        $usefacebook = true;
    }

    // show current user and avatar
    if ( is_user_logged_in() ) {
       
        global $current_user;
        $current_user = wp_get_current_user();
        $authorurl = get_author_posts_url( $current_user->ID, $current_user->user_nicename );
        
        // see if user has a facebook id in our system, show that avatar. otherwise, show regular gavatar
        if ($usefacebook) {
            $fbuid = get_user_meta($current_user->ID, 'fbuid');	
        }
    	echo '<div id="login-profile-avatar"><a href="' . $authorurl . '">';
    	if (!empty($fbuid) && $usefacebook) { 
    	    echo '<fb:profile-pic size="square" width="55" height="55" uid="' . $fbuid . '" linked="false"></fb:profile-pic>';
    	} else {
    	    echo get_avatar( $current_user->ID, 55, '', "View profile");
    	}
    	echo '</a></div>';
    
        
        
        $logouturl = wp_logout_url( "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'] );/* redirect URL */
        // user meta
        echo '<div id="login-profile-meta">';
            echo '<p id="login-profile-name">' . $current_user->display_name . '</p>';
            echo '<p id="login-profile-connected">Connected!</p>';
            echo '<p id="login-profile-url"><a href="' . $authorurl . '">View Profile</a></p>';
            echo '<p id="login-profile-logout"><a href="' . $logouturl . '">Log out</a></p>';
        echo '</div>';
   
   
    } else {
        
        /*
        if ($usefacebook) {
            echo '<p><fb:login-button v="2" perms="email" onlogin="sfc_update_user_details();"><fb:intl>Connect with Facebook</fb:intl></fb:login-button></p>';
        }*/
        
        $loginurl = wp_login_url( "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'] );/* redirect URL */
        echo '<div id="login-login">';
            echo '<a href="' . $loginurl . '">Log in</a>';
        echo '</div>';
        
    }
echo '</div>';
?>